﻿using DevExpress.XtraEditors.Controls;
using DevTeam;

using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class ProductTag : XPopupForm
    { 
        BindingSource bsCategory;
        BindingSource bsTag;

        public ProductTag()
        {
            InitializeComponent();
        }

      

        public void BindData()
        {
            GetDetails("ProductTag", "GetProductTag");

            DataRelation relation = new DataRelation("ProductTag2ProductTag",
                ds.Tables["ProductTag"].Columns["ProductTagId"],
                ds.Tables["ProductTag"].Columns["ParentId"]);
            ds.Relations.Add(relation);

            bsCategory = new BindingSource(ds, "ProductTag");
            bsTag = new BindingSource(bsCategory, "ProductTag2ProductTag");

            bsCategory.Filter = "ParentId is null";
            bsTag.Filter = "ParentId is not null";

            gcKategori.DataSource = bsCategory;
            gcTag.DataSource = bsTag;
        }


        private void frmUser_Load(object sender, EventArgs e)
        {
            BindData();
        }

        private void gvKategori_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            DataRow dr = ((DataRowView)e.Row).Row;
            dr["UserId"] = WhoAmI;
            dr["Deleted"] = false;
        }

        private void gvTag_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            DataRow dr = ((DataRowView)e.Row).Row;
            dr["UserId"] = WhoAmI;
            dr["Deleted"] = false;
        }

        private void gvKategori_InvalidRowException(object sender, DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs e)
        {
            e.ExceptionMode = ExceptionMode.Ignore;
        }

        private void gvTag_InvalidRowException(object sender, DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs e)
        {
            e.ExceptionMode = ExceptionMode.Ignore;
        }

        private void bbiKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvTag.EndEditing();
            gvKategori.EndEditing();

            TAM.ProductTagTableAdapter = new ConfExpert.Datasets.MyDataTableAdapters.ProductTagTableAdapter();

            TAM.ProductTagTableAdapter.Update(ds.ProductTag);
        }
    }
}